package org.javaboy.account.service;

import org.javaboy.account.mapper.AccountMapper;
import org.javaboy.account.model.Account;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

@Service
public class AccountService {

    @Autowired
    AccountMapper accountMapper;

    public Map<String, Object> deduce(Integer account, Double money) {
        Account a = accountMapper.selectById(account);
        if (a == null) {
            throw new RuntimeException("账户不存在");
        }
        if(a.getMoney() < money) {
            throw new RuntimeException("账户余额不足");
        }
        accountMapper.deduce(account,money);
        Map<String, Object> map = new HashMap<>();
        map.put("result", "扣款成功");
        return map;
    }
}
